package com.putao.album.util;

import android.graphics.Bitmap;
import android.graphics.Matrix;

import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;

/**
 * Created by chen on 15-5-19.
 */
public class RotateBitmapDisplayer implements BitmapDisplayer {
    private int orientation;

    /**
     * @param orientation 图片旋转的方向
     */
    public RotateBitmapDisplayer(int orientation) {
        this.orientation=orientation;
    }

    @Override
    public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
        if (!(imageAware instanceof ImageViewAware)) {
            throw new IllegalArgumentException("ImageAware should wrap ImageView. ImageViewAware is expected.");
        }
        Matrix m = new Matrix();
        m.setRotate(orientation);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
        imageAware.setImageBitmap(bitmap);
    }
}
